package POS.Interface;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * A POS System for a
 * small restaurant.
 * 
 * Maeghan Colvin and Jennifer Haveman
 * CSC 289 0B01
 * February 13, 2014
 */

public class MainFrame extends JFrame
{
    // Variables
    private JPanel mainPanel;               // Holds the mainPanel
    private JPanel clockInOutPanel;         // Holds the Clock in pad
    private JPanel optionsPanel;            // Holds clock in, out, and etc options
    private JToggleButton clockInButton, clockOutButton, posButton;
    private ButtonGroup optionsGroup;       // Holds the toggle buttons
    private String sqlStatement;            // Determines proper sqlStatement
    private Integer employeeNumber;
    
    /**
     * Constructor
     */
    public MainFrame() 
    {
        // Set title.
        this.setTitle("I Don't Know Eatery");
        
        // Close program option.
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        // Add mainPanel
        this.buildMainPanel();
        this.add(mainPanel);
        
        // Set resizable false, pack, and view.
        //this.setResizable(false);
        this.pack();
        this.setVisible(true);
    }
    
    /**
     * The buildMainPanel builds the 
     * mainPanel.
     */
    
    private void buildMainPanel() 
    {
        // Create mainPanel
        this.mainPanel = new JPanel(new BorderLayout());
        this.mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        
        // Set layout and border for optionsPanel
        optionsPanel = new JPanel(new GridLayout(0,3));
        optionsPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        
        // Create ButtonGroup and options buttons
        optionsGroup = new ButtonGroup();
        clockInButton = new JToggleButton("Clock In");
        clockInButton.setMnemonic(KeyEvent.VK_I);
        clockInButton.addActionListener(new optionsActionListener());
        clockOutButton = new JToggleButton("Clock Out");
        clockOutButton.setMnemonic(KeyEvent.VK_O);
        posButton = new JToggleButton("Menu");
        posButton.setMnemonic(KeyEvent.VK_M);
        
        // Add option buttons to optionsGroup
        optionsGroup.add(clockInButton);
        optionsGroup.add(clockOutButton);
        optionsGroup.add(posButton);
        
        // Add option buttons to optionsPanel
        optionsPanel.add(clockInButton);
        optionsPanel.add(clockOutButton);
        optionsPanel.add(posButton);
        
        // Add the Clock in/out screen.
        clockInOutPanel = new ClockInOutPanel();
        mainPanel.add(clockInOutPanel, BorderLayout.CENTER);
        mainPanel.add(optionsPanel, BorderLayout.SOUTH);
    }
    
    /**
     * The databaseStatement determines
     * the selected option button.
     * @return
     */
    public String databaseStatement()
    {
        //employeeNumber = ;
        if (clockInButton.isSelected())
        {
             sqlStatement = "UPDATE Payroll " + 
                            "SET Clock_In = 'Y' " +
                            "WHERE employeeID = 100";
        }
        return sqlStatement;
    }
    
    /**
     * The optionsActionListener receives
     * the proper sqlStatement for the option buttons.
     */
    
    private class optionsActionListener implements ActionListener 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        { 
            // Determine which options button is selected
            sqlStatement = databaseStatement();
            System.out.print(sqlStatement);
        }
    }
}
